﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Fc.报表
{
    public class JinDuData
    {
        public decimal[] Data = new decimal[270];

        public void QueryData(int fenchang,int scx, int chanpin, DateTime d1, DateTime d2, DateTime d3)
        {
            if (scx == 0) scx = 1;
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "生产日报数据";
            Cmd.CommandType = CommandType.StoredProcedure;

            Cmd.Parameters.Add(new SqlParameter("@分厂ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, fenchang));
            Cmd.Parameters.Add(new SqlParameter("@生产线", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, scx));

            Cmd.Parameters.Add(new SqlParameter("@产品类别ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, chanpin));
            Cmd.Parameters.Add(new SqlParameter("@d1", SqlDbType.Date, 3, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, d1));
            Cmd.Parameters.Add(new SqlParameter("@d2", SqlDbType.Date, 3, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, d2));
            Cmd.Parameters.Add(new SqlParameter("@d3", SqlDbType.Date, 3, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, d3));

            SqlDataReader Reader = Cmd.ExecuteReader();
            int x = 0;
            int gongduan;
            while (Reader.Read())
            {
                if (Reader.IsDBNull(2)) continue;
                if ((int)Reader["类别"] == 0)
                {
                    x = 0;
                }
                else if ((int)Reader["类别"] == 1)
                {
                    x = 120;
                }
                else
                {
                    x = 240;
                }
                gongduan=(int)Reader["工段"];
                if ( gongduan> 0 && gongduan <= 4)
                {
                    x += (gongduan - 1) * 30;
                }

                Data[x + 0] = (int)Reader["计划支数"];
                Data[x + 1] = (decimal)Reader["计划重量"];
                Data[x + 2] = (int)Reader["投入支数"];
                Data[x + 3] = (decimal)Reader["投入重量"];
                Data[x + 4] = (int)Reader["机紧1"];
                Data[x + 5] = (int)Reader["机紧2"];
                Data[x + 6] = (int)Reader["静水压"];
                Data[x + 7] = (int)Reader["称测支数"];
                Data[x + 8] = (decimal)Reader["称测长度"];
                Data[x + 9] = (decimal)Reader["称测重量"];
                Data[x + 10] = (int)Reader["包装支数"];
                Data[x + 11] = (int)Reader["包装捆数"];
                Data[x + 12] = (decimal)Reader["包装长度"];
                Data[x + 13] = (decimal)Reader["包装重量"];
                Data[x + 14] = (int)Reader["入库支数"];
                Data[x + 15] = (int)Reader["入库捆数"];
                Data[x + 16] = (decimal)Reader["入库长度"];
                Data[x + 17] = (decimal)Reader["入库重量"];
                Data[x + 18] = (int)Reader["未入库支数"];
                Data[x + 19] = (decimal)Reader["未入库重量"];

                Data[x + 20] = (int)Reader["车丝1"];
                Data[x + 21] = (int)Reader["车丝2"];
                Data[x + 22] = (int)Reader["车丝3"];
                Data[x + 23] = (int)Reader["车丝4"];
                Data[x + 24] = (int)Reader["车丝5"];
                Data[x + 25] = (int)Reader["车丝6"];
                Data[x + 26] = (int)Reader["车丝7"];
                Data[x + 27] = (int)Reader["车丝8"];
                Data[x + 28] = (int)Reader["车丝9"];
                Data[x + 29] = (int)Reader["车丝10"];

            }
            Reader.Close();
            Reader.Dispose();
            Cmd.Dispose();
            Conn.Close();
            Conn.Dispose();
        }
    }
}
